from rest_framework import serializers
from certificate_manager.models import UserTag
from certificate_manager.serializers import *

class UserTagSerializer(serializers.ModelSerializer):

    class Meta:
        model = UserTag
        fields = ['name', 'users']

    def to_representation(self, user_tag):
        repr = super().to_representation(user_tag)
        user_list = [UserSerializer(u).data for u in user_tag.users.all()]
        repr['users'] = user_list

        # 然后将UserTag给搞出来
        return repr

